package gameStates.gui;

import org.fenggui.util.ILogSystem;
import org.fenggui.util.Log;

import gameStates.absGamesStates.gui.AbsMenuState;
import gameStates.absGamesStates.network.AbsClientState;
import gameStates.absGamesStates.network.AbsServerState;
import gameStates.passes.AbsPassManagerState;
import interfaces.menu.AbsMenu;
import interfaces.menu.Menu;

/**
 * Implements a {@link GUIState} thats used for the main-menu.
 * 
 * @author Wasserleiche
 */
public class MenuState extends AbsMenuState {
	
	/**
	 * Constructs a new MenuState and creates a new {@link Menu}.
	 */
	public MenuState(AbsPassManagerState passManagerState, AbsClientState clientState, AbsServerState serverState) {
		super(passManagerState, true, clientState, serverState);
		
		Log.setLogSystem(new ILogSystem() {
			@Override
			public void warn(String warn, Object... vars) {}
			@Override
			public void error(String error, Throwable ex, Object... vars) {}
			@Override
			public void error(String error, Object... vars) {}
			@Override
			public void debug(String debug, Object... vars) {}
		});
				
		initInterface();
	}
	
	/**
	 * Creates a new {@link Menu} that shall be displayed in this MenuState.
	 */
	public void initInterface() {
		interfaceElement = new Menu(this);
	}
	
	/**
	 * Enables/disables the continue-button of the current {@link Menu}.
	 * @param enable true, if the continue-button shall be enabled. false, else.
	 */
	@Override
	public void enableContinueButton(boolean enable) { getMenu().enableContinueButton(enable); }
	
	/**
	 * Calls the {@link Menu} if there is an active {@link Game} or not.
	 * @param gameStarted true, if there is an active {@link Game}. false, if not.
	 */
	@Override
	public void setGameStarted(boolean gameStarted) { getMenu().setGameStarted(gameStarted); }
	
	@Override
	public AbsMenu getMenu() { return (AbsMenu)interfaceElement; }
	
	/**
	 * Restores this MenuState. This method also creates a new {@link Menu}.
	 */
	@Override
	public void restore() {		
		super.restore();
		initInterface();
		enableContinueButton(gameInitialized);
		setGameStarted(gameInitialized);
	}
}